package com.ruoyi.api.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSON;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzXiezilou;
import com.ruoyi.system.service.IDzXiezilouService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商铺写字楼Controller
 * 
 * @author ruoyi
 * @date 2023-08-17
 */
@RestController
@RequestMapping("/api/xiezilou")
public class DzXiezilouApiController extends BaseController
{
    @Autowired
    private IDzXiezilouService dzXiezilouService;

    /**
     * 查询商铺写字楼列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DzXiezilou dzXiezilou)
    {
        startPage();
        List<DzXiezilou> list = dzXiezilouService.selectDzXiezilouListWeb(dzXiezilou);
        return getDataTable(list);
    }

    @PostMapping("/list2")
    public TableDataInfo list2(@RequestBody DzXiezilou dzXiezilou)
    {
        startPage();
        List<DzXiezilou> list = dzXiezilouService.selectDzXiezilouListWeb(dzXiezilou);
        return getDataTable(list);
    }

    /**
     * 导出商铺写字楼列表
     */
    @Log(title = "商铺写字楼", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzXiezilou dzXiezilou)
    {
        List<DzXiezilou> list = dzXiezilouService.selectDzXiezilouListWeb(dzXiezilou);
        ExcelUtil<DzXiezilou> util = new ExcelUtil<DzXiezilou>(DzXiezilou.class);
        util.exportExcel(response, list, "商铺写字楼数据");
    }

    /**
     * 获取商铺写字楼详细信息
     */
    @GetMapping(value = "/{spId}")
    public AjaxResult getInfo(@PathVariable("spId") Long spId)
    {
        return AjaxResult.success(dzXiezilouService.selectDzXiezilouBySpId(spId));
    }

    /**
     * 新增商铺写字楼
     */
    @Log(title = "商铺写字楼", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzXiezilou dzXiezilou)
    {
        return toAjax(dzXiezilouService.insertDzXiezilou(dzXiezilou));
    }

    /**
     * 修改商铺写字楼
     */
    @Log(title = "商铺写字楼", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzXiezilou dzXiezilou)
    {
        return toAjax(dzXiezilouService.updateDzXiezilou(dzXiezilou));
    }

    /**
     * 删除商铺写字楼
     */
    @Log(title = "商铺写字楼", businessType = BusinessType.DELETE)
	@DeleteMapping("/{spIds}")
    public AjaxResult remove(@PathVariable Long[] spIds)
    {
        return toAjax(dzXiezilouService.deleteDzXiezilouBySpIds(spIds));
    }
}
